import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {
        String x = "";
        do {
            //生成一个随机数
            int num = (int)(Math.random()*100)+1;
            System.out.println(num);

            int max =100;
            int min =1;

            //接受用户输入数字
            Scanner sc = new Scanner(System.in);

            for (int i = 0; i<=7;i++){
                System.out.println("请输入(1~100内)你要猜的数字:");
                int guessNumber = sc.nextInt();
                if (i==7){
                    if (guessNumber == num){
                        System.out.println("恭喜你，第7次猜对了");
                    }else {
                        System.out.println("很遗憾，次数用完了");
                        break;
                    }
                }

                // 判断输入的数字是否符合
                if (guessNumber > num) {
                    max = guessNumber;
                    System.out.println("你猜大了");
                } else if (guessNumber < num) {
                    min = guessNumber;
                    System.out.println("你猜小了");
                }else {
                    System.out.println("恭喜你，猜对了");
                    break;
                }
            }
            System.out.println("请输入y，否则游戏结束！");
            x = sc.next();
        }while ("y".equals(x));
        System.out.println("游戏结束!");
    }
}
